package jbrowser.gui;

import java.io.PrintWriter;
import java.io.StringWriter;

public class ErrorPage extends AbstractPage {

    public ErrorPage(String title, String details) {
        initComponents();
        txtDetails.setText(details);
        lblTitle.setText(title);
    }

    public ErrorPage(Exception exception) {
        initComponents();
        StringWriter sw = new StringWriter();
        exception.printStackTrace(new PrintWriter(sw, true));
        String stacktrace = sw.toString();
        txtDetails.setText(stacktrace);
        lblTitle.setText(exception.getMessage());
    }

    @Override
    public String getTitle() {
        return "Error";
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblTitle = new javax.swing.JLabel();
        scrollPane = new javax.swing.JScrollPane();
        txtDetails = new javax.swing.JTextArea();

        setLayout(new java.awt.BorderLayout(5, 5));

        lblTitle.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        lblTitle.setForeground(java.awt.Color.red);
        lblTitle.setText("ERROR");
        lblTitle.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        add(lblTitle, java.awt.BorderLayout.NORTH);

        txtDetails.setColumns(20);
        txtDetails.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
        txtDetails.setRows(5);
        scrollPane.setViewportView(txtDetails);

        add(scrollPane, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel lblTitle;
    private javax.swing.JScrollPane scrollPane;
    private javax.swing.JTextArea txtDetails;
    // End of variables declaration//GEN-END:variables
}
